<template>
  <div class="post-comment">
    <van-nav-bar :title="`${comment.reply_count}`+'条评论'" :fixed="true">
      <van-icon slot="left" name="cross" @click="$emit('close',false)"></van-icon>
    </van-nav-bar>
    <div class="comment-con">

    <comment-item :comment="comment"></comment-item>

    <comment-list :source="comment.com_id" type="c" :list="commentList"></comment-list>
    </div>

    <!-- 底部 -->
    <div class="article-bootom">
      <van-button type="default" round size="small" @click="isPostShow = true">写评论</van-button>
    </div>

     <van-popup v-model="isPostShow" position="bottom">
      <postComment :target="comment.com_id" :article-id="articleId" @post-success="onPostSuccess" />
    </van-popup>

  </div>
</template>

<script>
import commentItem from './comment-item.vue'
import commentList from './comment-list.vue'
import postComment from './post-comment.vue'
export default {
  name: 'commentReply',
  data () {
    return {
      message: '',
      isPostShow: false,
      commentList: []
    }
  },
  components: {
    commentItem,
    commentList,
    postComment
  },
  props: {
    comment: {
      type: Object,
      required: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }

  },
  methods: {
    onPostSuccess (comment) {
      this.commentList.unshift(comment)
      this.comment.reply_count++
      this.isPostShow = false
    }
  }
}
</script>

<style scoped lang="less">
.article-bootom {
  position: fixed;
  bottom: 0;
  height: 50px;
  width: 100%;
  background-color: #fff;
  display: flex;
  justify-content: space-around;
  align-items: center;
  .van-button {
    width: 180px;
  }
}

.comment-con{
    margin-top: 40px;
}
</style>
